<script>
import { mapActions } from "vuex";
import { Base64, _decrypt, $Toast } from "@/utils";
export default {
    beforeCreate() {
        wx.hideTabBar();
    },
    onLaunch(options) {
        this.getSystemInfo();
        this.getAdlist();
        wx.hideTabBar();
        this.init();
        (() => {
            let counter = 0;
            let timer = setInterval(() => {
                counter++;
                wx.hideTabBar();
                if (counter > 10) {
                    clearInterval(timer);
                }
            }, 300);
        })();
        // Do something initial when launch.
        /*  console.log(
            "App onLaunch, env文件自定义的环境变量VUE_APP_TEST值:",
            process.env.VUE_APP_TEST
        ); */
    },
    onShow(options) {
        // Do something when show.
        // console.log("App onShow");
    },
    onHide() {
        // Do something when hide.
        // console.log("App onHide");
    },
    mounted() {},
    onError(msg) {
        /*         wx.showToast({
            title: "خاتالىق كۆرۈلدى", //提示的内容,
            icon: "info", //图标,
            duration: 500, //延迟时间,
            mask: true //显示透明蒙层，防止触摸穿透
        });
        setTimeout(() => {
            wx.navigateBack({
                delta: 1 //返回的页面数，如果 delta 大于现有页面数，则返回到首页,
            });
        }, 500); */
        // console.log("App onError");
        console.log(msg);
    },
    globalData() {
        return {
            a: "I am global data"
        };
    },
    beforeCreate() {},
    methods: {
        ...mapActions(["getSystemInfo"]),
        init() {
            let seenVideos = wx.getStorageSync("seenVideos");
            if (!seenVideos) {
                let seenVideos = [];
                wx.setStorageSync("seenVideos", seenVideos);
            }
            // 判断用户是否登录，并且是不是为vip用户
            let userInfo = wx.getStorageSync("userInfo");
            if (userInfo && userInfo.uid) {
                this.$http
                    .get("/mpGetUserStatus", { uid: userInfo.uid })
                    .then(res => {
                        if (res.code == "001") {
                            let infoStr = _decrypt(res.data, "yusupturak");
                            infoStr = Base64.decode(infoStr);
                            let info = JSON.parse(infoStr);
                            // 判断后端是否传了isVip字段
                            if (info && typeof info == "object" && info.isVip) {
                                this.$store.commit("SET_USER", info);
                            } else {
                                let now = Date.now();
                                if (info.startTime && info.endTime > now) {
                                    info.isVip = 1;
                                    this.$store.commit("SET_USER", info);
                                } else {
                                    this.$store.commit("SET_USER", info);
                                }
                            }
                        }
                    });
            }
        },
        async getAdlist() {
            let res = await this.$http.get("/getSwiper");
            this.$store.commit("SET_CONF", {
                canPlay: res.canPlay, //电影可否播放
                iosPay: res.iosPay, //IOS付款
                forceLogin: res.forceLogin, //强制登陆
                lockPay: res.lockPay,
                showAd: res.showAd
            });
            this.$store.commit("SET_ELAN", res.elan);
            this.$store.commit("SET_AD", res.list);
        }
    }
};
</script>
<style lang="scss">
@import url("./assets/CSS/global.css");
@import url("./assets/CSS/iconfont.css");
page {
    font-family: "ALKATIP UI" !important;
}
.lock-bg {
    position: fixed;
    z-index: 999;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.6);
    top: 0;
    left: 0;
}
</style>

